@extends('Admin.layouts.common')

@section('content')
    <div class="container myContainer">

        <button class="btn btn-info searchBtn" onclick="$('.search_box').slideToggle();">搜索/筛选</button>
        <div class="search_box">
            <form id="search_form" method="GET">
            	<label>
                    Uid：<br>
                    <input type="text" name="uid" class="form-control search_form_control" value="{{$_search['uid']}}">
                </label>
                <label>
                    邀请码：<br>
                    <input type="text" name="invitation_code" class="form-control search_form_control" value="{{$_search['invitation_code']}}">
                </label>
                <label>
                    手机号<br>
                    <input type="text" name="phone" class="form-control search_form_control" value="{{$_search['phone']}}">
                </label>
                
                <button class="btn btn-primary" type="submit">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>
            </form>
        </div>

        <div id="order_tag"></div>

        <div class="table-responsive">
            <table class="table">
                <caption>{{$title??'合伙人'}}</caption>
                <thead>
                    <tr>
                        <th>Uid</th>
                        <th>用户名</th>
                        <th>手机号</th>
                        <th>账户累计收益</th>
                        <th><a href="javascript:void(0);" data-order="total_money">总收益</a></th>
                        <th><a href="javascript:void(0);" data-order="money">合伙人余额</a></th>
                        <th>师傅id</th>
                        <th>合伙人id</th>
                        <th><a href="javascript:void(0);" data-order="td_count">徒弟人数</a></th>
                        <th>徒弟活跃数</th>
                        <th><a href="javascript:void(0);" data-order="ts_count">徒孙人数</a></th>
                        <th>徒孙活跃数</th>
                        <th>总跃数</th>
                        <th>高度</th>
                        <th>邀请码</th>
                        <th><a href="javascript:void(0);" data-order="all_count">团队人数</a></th>
                        <th>合伙人数</th>
                        <th>会员等级</th>
                        <th>升级超级会员权限</th>
                        <th>软文权限</th>
                        <th>微信号</th>
                        <th>微信导流</th>
                        <th>注册时间</th>
                        <th>升级时间</th>
                        <th>来源</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($list->items() as $item)
                        <tr id="tr_{{$item->id}}">
                            <td>{{ $item->uid }}</td>
                            <td><a href="javascript:;" onclick="layx.iframe('localsite','详细','/user/partner_info/'+{{$item->uid}})"> {{ urldecode($item->user->nickname) }} </a></td>
                            <td>{{ $item->phone }}</td>
                            <td>{{ $item->profit??0 }}</td>
                            <td>{{ $item->total_money??'' }}</td>
                            <td><a href="/user/money/{{$item->uid}}">{{ $item->money }}</a></td>
                            <td>{{ $item->user->tj_id }}</td>
                            <td>{{ $item->from_uid }}</td>
                            <td>{{ $item->td_count }}</td>
                            <td>{{ $item->td_huoyue }}</td>
                            <td>{{ $item->ts_count }}</td>
                            <td>{{ $item->ts_huoyue }}</td>
                            <td>{{ $item->total_huoyue }}</td>
                            <td>{{ $item->hight}}</td>
                            <td><a href="javascript:;" onclick="invitation_code({{$item->uid}})"> {{ $item->invitation_code }}</a></td>
                            <td>{{ ($item->right-$item->left-1)/2 }}</td>
                            <td><a href="/user/separate_index?_search=from_uid={{$item->uid}}"> {{ $item->from_count }}</a></td>
                            <td>
                            	@if($item->user_level==0)
                                普通会员
                                @elseif($item->user_level==1)
                                超级会员
                                @elseif($item->user_level==2)
                                合伙人
                                @endif
                           	</td>
                            <td><a id="a_{{$item->uid}}" href="javascript:;" onclick="super_priv({{$item->uid}},this)">{{$item->jurisdiction==1?'有':'否'}}</a></td>
                            <td><a id="b_{{$item->uid}}" href="javascript:;" onclick="adv_priv({{$item->uid}},this)">{{$item->adv_switch==1?'有':'无'}}</a></td>
                            <td>{{ $item->wechat_number }}</td>
                            <td>
                                @if(!empty($item->wechat_number))
                                    @if($item->diversion==0)
                                    <a href="javascript:;" onclick='layx.confirm("导流","确定要开通微信导流吗？",function(){
    $.post("/user/ajax_diversion/{{$item->id}}",{diversion:2});
    layx.destroy(id);
    window.location.reload();
});'>开通微信导流</a>
                                    @elseif($item->diversion==2)
                                <a href="javascript:;" onclick='layx.confirm("导流","确定要关闭微信导流吗？",function(){
    $.post("/user/ajax_diversion/{{$item->id}}",{diversion:0});
    layx.destroy(id);
    window.location.reload();
});'>关闭微信导流</a>
                                    @else
                                    <a href="javascript:;" onclick='layx.confirm("导流","确定要开通微信导流吗？",function(){
    $.post("/user/ajax_diversion/{{$item->id}}",{diversion:2});
    layx.destroy(id);
    window.location.reload();
});'>开通微信导流</a>
                                    @endif
                                @else
                                无微信号
                                @endif
                            </td>
                            <td>{{ date('Y/m/d H:i:s',$item->user->time) }}</td>
                            <td>{{ date('Y/m/d H:i:s',$item->up_partner_time) }}</td>
                            <td>{{ $item->user->source }}</td>
                            <td>
                                <a href="/user/nodes/{{ $item->uid }}">查看团队</a>

                                <a href="/cash/index?_search=uid={{$item->uid}}">提现记录</a>
                            
                            </td>
                        </tr>
                    @empty
                        <tr><td class="text-center" colspan="9">没有数据</td></tr>
                    @endforelse
                </tbody>
            </table>
            <div class="text-center">
                {{ $list->links() }}
            </div>
        </div>

    </div>
    <link href="{{ asset('libs/select2/select2.min.css') }}" rel="stylesheet">
<script src="{{ asset('libs/select2/select2.min.js') }}"></script>
<script src="{{ asset('libs/select2/zh-CN.js') }}"></script>
<script type="text/javascript">
$("#uid").select2({
    language: "zh-CN",
    ajax:{
        url: "/Users/ajax_select2_user",
        dataType: 'json',
        delay: 600,
        method: 'POST',
        data: function (params) {
            return {
                name: params.term,
            };
        },
        processResults: function (data, params) {
            return {
                results: data.data,
            };
        },
        cache: true
    },
    placeholder:'请输入手机号码',
    allowClear: true,
    escapeMarkup: function (markup) { return markup; },
    minimumInputLength: 11,
    templateResult: function(repo){ return repo.name; },
    templateSelection: function(repo){ 
        if(repo.id === ""){
            return repo.text
        }else{
            if(repo.selected == true){
                return repo.text
            }
            return repo.name
        }
         
    } 
});
</script>

<script type="text/javascript">
$.ajaxSetup({
    headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
})

function ajax_delete_theme(id){
    if(confirm('确认删除吗?')){
        $.post("/admins/ajax_delete_admin/"+id,{},function(json){
            if(json.status==1){
                $("#tr_"+json.data).fadeOut();
            }else{
                alert(json.info);
            }
        },"json");
    } 
}

function change_diversion(id,obj){
    var diversion = $(obj).val();
    $.post("/user/ajax_up_diversion/"+id,{diversion:diversion},function(json){
            if(json.status==1){
                
            }else{
                alert(json.info);
            }
        },"json");
}

function invitation_code(uid){
    layx.iframe('localsite','邀请码','/user/ajax_invitation_code/'+uid);
}
function super_priv(uid,obj){
    var priv = $(obj).text();
    var jurisdiction = priv=='有'?0:1;
    $.post("/user/ajax_jurisdiction/"+uid,{uid:uid,jurisdiction:jurisdiction},function(json){
        if(json.status==1){
            $("a#a_"+json.uid).text(json.data);
        }else{
            alert("error");
        }

    },"json");
}

function adv_priv(uid,obj){
    var priv = $(obj).text();
    var adv_switch = priv=='有'?0:1;
    $.post("/user/ajax_adv_switch/"+uid,{uid:uid,adv_switch:adv_switch},function(json){
        if(json.status==1){
            $("a#b_"+json.uid).text(json.data);
        }else{
            alert("error");
        }

    },"json");
}
</script>
@endsection